<template>
	<view class="">
		<view class="margin-top content padding-lr bg">
			<view class="flex padding-tb u-border-bottom" @click="goIM(user.id)" v-for="(user,index) in users"
				style="margin-bottom:10rpx;">
				<view>
					<u-image shape="circle" width='80rpx' height="80rpx" :src="user.avr"></u-image>
				</view>
				<view class="flex-sub margin-left-sm">
					<view class="flex justify-between">
						<view class="text-white">{{ user.nick }}</view>
						<view class="text-grey">{{user.chat.localTime}}</view>
					</view>
					<view class="flex justify-between">
						<view class="text-grey">{{user.chat.msg}}</view>
						<view v-if="user.chat.sumUnReadChatNum > 0" style="">
							<view class="round"
								style="display: inline-block;background-color: #ff0000; color: #ffffff;padding: 2upx 8upx;">
								<u-icon></u-icon>{{user.chat.sumUnReadChatNum}}
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				users: [],
				userId: ''
			}
		},
		onShow() {
			this.userId = uni.getStorageSync("userId");
			this.getData();
		},
		methods: {
			goIM(id) {
				uni.navigateTo({
					url: '/pages/msg/im?id=' + id
				});
			},
		
			getData() {
				this.$myRequest({
					url: "/chat/getChatList/"+this.userId,
				}).then(r => {
					this.users = r.data.data;
					console.log(r.data.data);
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #111224;
	}

	.bg {
		background-color: #1E1F31;
	}
</style>
